package algorithm.binaryAlgorithm;

/**
 * @ClassName: CountPrimeSetBits
 * @Description TODO
 * @Author skywingking
 * @Date 2022/4/5 10:24 下午
 **/
public class CountPrimeSetBits {
    public int countPrimeSetBits(int left, int right) {
        int ans = 0;
        for (int x = left; x <= right; ++x) {
            if (isPrime(Integer.bitCount(x))) {
                ++ans;
            }
        }
        return ans;
    }

    private boolean isPrime(int x){
        if( x < 2){
            return false;
        }
        for(int i = 2; i * i <= x; i++){
            if( x % i == 0){
                return false;
            }
        }
        return true;
    }
}